package threads.wait;

public class MutiWaitTest {
    public static void main(String[] args) {
        Object lock = new Object();
        final int[] lockCount = {3};
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (lock) {
                    while (lockCount[0] >= 1) {
                        try {
                            System.out.println(lockCount[0] );
                            lock.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                    System.out.println("T1: I have get the result of t2,t3,t4");
                }
            }
        });
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (lock) {
                    lockCount[0]--;
                    lock.notify();
                    System.out.println("T2: I have done");
                }
            }
        });
        Thread t3 = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (lock) {
                    lockCount[0]--;
                    lock.notify();
                    System.out.println("T3: I have done");
                }
            }
        });
        Thread t4 = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (lock) {
                    lockCount[0]--;
                    lock.notify();
                    System.out.println("T4: I have done");
                }
            }
        });
        t1.start();
        t2.start();
        t3.start();
        t4.start();
    }
}
